/* GUI CONVERTED from adadcge.p (converter v1.76) Mon Apr 21 19:43:32 2003 */
/* adadcge.p - Change address code                                           */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.6.1.12 $                                                         */
/*                                                                           */
/* Change value of a specified address code.                                 */
/*                                                                           */
/* REVISION: 7.3      LAST MODIFIED: 02/10/94   BY: dpm *FL63*               */
/*                                   06/30/94   BY: rmh *FP15*               */
/*                                   08/31/94   BY: rmh *FQ64*               */
/* Oracle changes (share-locks)      09/11/94   BY: rwl *FR09*               */
/*                                   09/26/94   BY: jzs *GM54*               */
/* REVISION: 7.3      LAST MODIFIED: 01/12/96   BY: rxm *G0YC*               */
/* REVISION: 7.3      LAST MODIFIED: 04/19/96   BY: rxm *G1L3*               */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane         */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan        */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan        */
/* REVISION: 9.0      LAST MODIFIED: 03/10/99   BY: *M0B3* Michael Amaladhas */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan        */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 02/10/00   BY: *N06R* Steve Goeke       */
/* REVISION: 9.1      LAST MODIFIED: 08/11/00   BY: *N0KK* jyn               */
/* REVISION: 9.1      LAST MODIFIED: 10/26/00   BY: *N0T8* Vincent Koh       */
/* REVISION: 9.1      LAST MODIFIED: 02/06/01   BY: *N0VG* Jyoti Thatte      */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.6.1.11     BY: Katie Hilbert      DATE: 05/15/02  ECO: *P06H*  */
/* $Revision: 1.6.1.12 $    BY: Narathip W.        DATE: 04/17/03  ECO: *P0Q4*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/*                                                                           */
/*V8:ConvertMode=Maintenance                                                 */

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */
{cxcustom.i "ADADCGE.P"}

{pxpgmmgr.i}  /* Project X persistent procedure functions */

define shared variable addr1     like ad_addr.
define shared variable addr2     like ad_addr.
define shared variable i         as integer no-undo.
define shared variable num_rec   as integer no-undo.
define shared variable cnt_clear like mfc_logical.  /* mfcscgb.i */
define shared variable record_id as recid no-undo.
define shared variable type1     like ad_type.
define shared variable merge     like mfc_logical.
define shared frame b.
define variable jk      as integer.
define variable counter as integer no-undo.
define buffer lsmstr for ls_mstr.
define buffer gltdet for glt_det.

define shared variable nomaint as character format "x(80)"
   {adlsmt.i}  /* Variable initialization */

   {gpfilev.i}

   do with frame b:

   {&ADADCGE-P-TAG1}
   FORM /*GUI*/ 
      file_desc    label "Data Set" format "x(30)"
      num_rec      label "Records Updated"
   with frame b width 80 down no-attr-space THREE-D /*GUI*/.

   {&ADADCGE-P-TAG2}

   /* SET EXTERNAL LABELS */
   setFrameLabels(frame b:handle).

   /* Change customer numbers IN ar_mstr.ar_nbr  */
   /*   For payment transactions */
   for each ar_mstr exclusive-lock where ar_nbr begins addr1:
      if ar_type = "p" and substring(ar_nbr,1,8) = addr1 then do:

         /* Change cust numbers in glt_doc and gltr_doc */
         for each glt_det
            where glt_tr_type = "AR" and
                  glt_doc_type = "P" and
                  glt_doc = ar_nbr no-lock:
            find gltdet where recid(gltdet) = recid(glt_det)
            exclusive-lock.
            gltdet.glt_doc = string(addr2,"x(8)") + substring(ar_nbr,9).
         end.

         for each gltr_hist exclusive-lock
            where gltr_doc_typ = "P"
              and gltr_eff_dt = ar_effdate
              and gltr_doc = ar_nbr
            use-index gltr_doctype:
            gltr_doc = string(addr2,"x(8)") + substring(ar_nbr,9).
         end.
      end.
   end.

   for each ar_mstr exclusive-lock where ar_nbr begins addr1:
      if ar_type = "p" and substring(ar_nbr,1,8) = addr1 then do:
         for each ard_det exclusive-lock where ard_nbr = ar_nbr:
            ard_nbr = string(addr2, "X(8)" ) + substring(ard_nbr,9).
         end.
         {&ADADCGE-P-TAG3}
         ar_nbr = string(addr2, "X(8)" ) + substring(ar_nbr,9).
      end.
   end.

   /****** CODE TO CHANGE PRM ADDRESS CODE ******/
   num_rec = 0.
   for each prj_mstr where prj_cust = addr1
         or prj_bill_to = addr1 or prj_ship_to = addr1
         or prj_eu_nbr = addr1 or prj_slspsn[1] = addr1
         or prj_slspsn[2] = addr1 or prj_slspsn[3] = addr1
         or prj_slspsn[4] = addr1
      exclusive-lock:
      if prj_cust = addr1 then prj_cust = addr2.
      if prj_bill_to = addr1 then prj_bill_to = addr2.
      if prj_ship_to = addr1 then prj_ship_to = addr2.
      if prj_eu_nbr = addr1 then prj_eu_nbr = addr2.
      do counter = 1 to 4:
         if prj_slspsn[counter] = addr1 then
            prj_slspsn[counter] = addr2.
      end.
      num_rec = num_rec + 1.
   end.

   /* DISPLAY PROJECT MASTER TABLE NAME AND RECORD COUNT */
   /* IN FRAME B                                         */
   {mfcscgb.i prj_mstr}

   num_rec = 0.
   for each pjd_det where pjd_eu_nbr = addr1
         or pjd_slspsn[1] = addr1 or pjd_slspsn[2] = addr1
         or pjd_slspsn[3] = addr1 or pjd_slspsn[4] = addr1
      exclusive-lock:
      if pjd_eu_nbr = addr1 then pjd_eu_nbr = addr2.
      do counter = 1 to 4:
         if pjd_slspsn[counter] = addr1 then
            pjd_slspsn[counter] = addr2.
      end.
      num_rec = num_rec + 1.
   end.

   /* DISPLAY SUBPROJECT DETAIL TABLE NAME AND RECORD COUNT */
   /* IN FRAME B                                            */
   {mfcscgb.i pjd_det}

   num_rec = 0.
   for each ins_mstr where ins_bill_to = addr1
      exclusive-lock:
      if ins_bill_to = addr1 then ins_bill_to = addr2.
      num_rec = num_rec + 1.
   end.

   /* DISPLAY INVOICE SCHEDULE MASTER TABLE NAME AND RECORD */
   /* COUNT IN FRAME B                                      */
   {mfcscgb.i ins_mstr}

   /****** END CODE TO CHANGE PRM ADDRESS CODE ******/

   /* Change address codes in external address xref */
   run changeInternalCodes in getHandle("adaxxr.p", true)
      (input  addr1,
       input  addr2).

   if merge then do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.

      num_rec = 0.
      for each ls_mstr exclusive-lock where ls_addr = addr1:
         /* Allow customer and enduser merge */
         if lookup(ls_type, nomaint) = 0 or ls_type = "enduser"
         then do:
            find lsmstr where
               lsmstr.ls_type = ls_mstr.ls_type
               and lsmstr.ls_addr = addr2 no-lock no-error.
            if not available lsmstr then ls_mstr.ls_addr = addr2.
            else delete ls_mstr.
            num_rec = num_rec + 1.
         end.
         else delete ls_mstr.
         release ls_mstr.
      end.
      {mfcscgb.i ls_mstr}
      find ad_mstr where ad_addr = addr1
      exclusive-lock no-error.
      /* Takes care of ship,remit&co */
      if available ad_mstr then do:
         /* Delete EDI ship IDs for this address */
         {gprun.i ""gpsfiddl.p"" "(input ad_addr)"}
/*GUI*/ if global-beam-me-up then undo, leave.

         delete ad_mstr.
      end.
   end.
   else do:
      {mfcscg.i ad_mstr ad_addr addr1 addr2}
      {mfcscg.i ad_mstr ad_ref addr1 addr2}
   end.
end.
